/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DaveSexton.DocProject.Sandcastle.BuildComponents.Editors
{
	public partial class CancelableBaseEditorDialog : Form
	{
		#region Public Properties
		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual SandcastleBuildComponent BuildComponent
		{
			get
			{
				return buildComponent;
			}
			set
			{
				if (value == null)
					throw new ArgumentNullException("value");

				if (buildComponent != value)
				{
					buildComponent = value;

					SetCaption(buildComponent);
					UpdateForBuildComponent(buildComponent);
				}
			}
		}
		#endregion

		#region Private / Protected
		private SandcastleBuildComponent buildComponent;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="CancelableBaseEditorDialog" /> class.
		/// </summary>
		protected CancelableBaseEditorDialog()
		{
			InitializeComponent();
		}
		#endregion

		#region Methods
		protected virtual void SetCaption(SandcastleBuildComponent component)
		{
			Text = string.Format(System.Globalization.CultureInfo.CurrentCulture, Text,
				component.Index + 1, System.IO.Path.GetFileName(component.ConfigurationFile));
		}

		protected virtual void UpdateForBuildComponent(SandcastleBuildComponent component)
		{
		}

		protected virtual bool SaveChanges()
		{
			return true;
		}

		protected virtual bool CancelChanges()
		{
			return true;
		}
		#endregion

		#region Event Handlers
		private void okButton_Click(object sender, EventArgs e)
		{
			if (SaveChanges())
				DialogResult = DialogResult.OK;
		}

		private void cancelButton_Click(object sender, EventArgs e)
		{
			if (CancelChanges())
				DialogResult = DialogResult.Cancel;
		}
		#endregion
	}
}